﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;
using System.Windows.Media;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.OperatorDecl"/>.
    /// </summary>
    public class OperatorDeclVM : MethodDeclVM
    {
        #region /* STATICS */

        internal static new void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(OperatorDecl),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new OperatorDeclVM((OperatorDecl)codeObject, isDescription, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.OperatorDecl"/>.
        /// </summary>
        public OperatorDeclVM(OperatorDecl operatorDecl, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(operatorDecl, isDescription, true, true, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.OperatorDecl"/> model.
        /// </summary>
        public OperatorDecl OperatorDecl
        {
            get { return (OperatorDecl)CodeObject; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        protected virtual Brush RenderBrush()
        {
            return OPERATOR_BRUSH;
        }

        internal override void RenderName(CodeRenderer renderer, RenderFlags flags)
        {
            renderer.RenderText(OperatorDecl.Symbol, RenderBrush(), this);
        }

        protected override void RenderStatement(CodeRenderer renderer, RenderFlags flags)
        {
            RenderFlags passFlags = (flags & RenderFlags.PassMask);
            if (_returnTypeVM != null)
                _returnTypeVM.Render(renderer, passFlags | RenderFlags.IsPrefix);
            renderer.RenderText(OperatorDecl.ParseToken + " ", KEYWORD_BRUSH, this);
            if (flags.HasFlag(RenderFlags.Description) && ParentVM is TypeDeclVM)
            {
                ((TypeDeclVM)ParentVM).RenderName(renderer, flags);
                renderer.RenderText(Dot.ParseToken, IDENTIFIER_BRUSH, this);
            }
            RenderName(renderer, flags);
        }

        #endregion
    }
}
